<?php

namespace App\Http\Requests\Backend\Setting;

use Illuminate\Foundation\Http\FormRequest;

class SettingBannerImageRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $method = $this->method();
        switch ($method){
            case 'POST':
                return [
                    'img_path' => 'bail|required|string',
                    'url' => 'nullable',
                    'title'=> 'nullable|required_with:url'
                ];
                break;
            case 'PUT':
                return [
                    'url' => 'nullable|string',
                    'title'=> 'nullable|required_with:url',
                    'img_path' => 'sometimes|required|string',
                    'is_show'=>'sometimes|in:1,2'
                ];
                break;
        }
    }

    public function messages()
    {
        return [
            'img_path.string' => '图片链接应为字符串',
            'img_path.required' => '图片链接必传',
            'is_show.in' => '显示类型传递错误',
            'title.required_with' => '标题字段必填'
        ];
    }
}